using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CallerID.Helpers;

namespace CallerID
{
    public class PopupFormSettings
    {
        private PopupFormDockStyle m_DockStyle = PopupFormDockStyle.DoleDesno;
        private Font m_FontPhone = null;
        private Font m_FontID = null;
        private Point m_Location = new Point(0, 0);
        private Size m_Size = new Size(280, 160);
        //private bool m_AutoSize = false;
        private Color m_ColorBack = Color.FromArgb(255, 255, 192);
        private Color m_ColorPhone = Color.Black;
        private Color m_ColorID = Color.Black;
        private int m_Opacity = 100;
        private bool m_NoBackground = false;

        private int m_RingTimeout = 6;
        private bool m_RingSoundEnabled = false;
        private string m_RingSound = string.Empty;

        [DefaultValue(PopupFormDockStyle.DoleDesno)]
        public PopupFormDockStyle DockStyle
        {
            get { return m_DockStyle; }
            set { m_DockStyle = value; }
        }
        public Font FontPhone
        {
            get { return m_FontPhone; }
            set
            {
                if(m_FontPhone != null) {
                    try { m_FontPhone.Dispose(); } catch { }
                    m_FontPhone = null;
                }
                m_FontPhone = value;
            }
        }
        public Font FontID
        {
            get { return m_FontID; }
            set
            {
                if(m_FontID != null) {
                    try { m_FontID.Dispose(); } catch { }
                    m_FontID = null;
                }
                m_FontID = value;
            }
        }
        [DefaultValue(typeof(Point), "0, 0")]
        public Point Location
        {
            get { return m_Location; }
            set { m_Location = value; }
        }
        [DefaultValue(typeof(Size), "260, 160")]
        public Size Size
        {
            get { return m_Size; }
            set { m_Size = value; }
        }
        /*
        [DefaultValue(false)]
        private bool AutoSize
        {
            get { return m_AutoSize; }
            set { m_AutoSize = false; }
        }
        */
        public Color ColorBack
        {
            get { return m_ColorBack; }
            set { m_ColorBack = value; }
        }
        public Color ColorPhone
        {
            get { return m_ColorPhone; }
            set { m_ColorPhone = value; }
        }
        public Color ColorID
        {
            get { return m_ColorID; }
            set { m_ColorID = value; }
        }
        [DefaultValue(100)]
        public int Opacity
        {
            get { return m_Opacity; }
            set { m_Opacity = value; }
        }
        [DefaultValue(false)]
        public bool NoBackground
        {
            get { return m_NoBackground; }
            set { m_NoBackground = value; }
        }

        [DefaultValue(6)]
        public int RingTimeout
        {
            get { return m_RingTimeout; }
            set { m_RingTimeout = value; }
        }
        [DefaultValue(false)]
        public bool RingSoundEnabled
        {
            get { return m_RingSoundEnabled; }
            set { m_RingSoundEnabled = value; }
        }
        public string RingSound
        {
            get { return m_RingSound; }
            set { m_RingSound = value; }
        }

        public PopupFormSettings()
        {
            SetDefaults();
        }
        ~PopupFormSettings()
        {
            this.FontPhone = null;
            this.FontID = null;
        }

        public PopupFormSettings(PopupFormSettings p)
        {
            SetDefaults();
            if(p != null) {
                this.DockStyle = p.DockStyle;
                if(p.FontPhone != null) this.FontPhone = p.FontPhone.Clone() as Font;
                if(p.FontID != null) this.FontID = p.FontID.Clone() as Font;
                this.Location = p.Location;
                this.Size = p.Size;
                //this.AutoSize = p.AutoSize;
                if(p.ColorBack != Color.Empty) this.ColorBack = p.ColorBack;
                if(p.ColorPhone != Color.Empty) this.ColorPhone = p.ColorPhone;
                if(p.ColorID != Color.Empty) this.ColorID = (p.ColorID);
                this.Opacity = p.Opacity;
                this.NoBackground = p.NoBackground;
                this.RingTimeout = p.RingTimeout;
                this.RingSoundEnabled = p.RingSoundEnabled;
                this.RingSound = p.RingSound;
            }
        }

        public void SetDefaults()
        {
            this.DockStyle = PopupFormDockStyle.DoleDesno;
            this.FontPhone = new Font("Tahoma", 18F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(238)));
            this.FontID = new Font("Tahoma", 15.75F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(238)));
            this.Location = new Point(0, 0);
            this.Size = new Size(260, 160);
            //this.AutoSize = false;
            this.ColorBack = Color.FromArgb(255, 255, 192);
            this.ColorPhone = Color.Black;
            this.ColorID = Color.Black;
            this.Opacity = 100;
            this.NoBackground = false;
            //this.RingTimeout = 6;
            //this.RingSoundEnabled = false;
            //this.RingSound = PathHelpers.GetWindowsPath() + "Media\\ringin.wav";
        }

        public string GetRingSoundBrowseDirectory()
        {
            string path = PathHelpers.GetFilePath(this.RingSound);
            if(string.IsNullOrEmpty(path)) path = PathHelpers.GetWindowsPath() + "Media\\";
            return path;
        }
    }

    public enum PopupFormDockStyle
    {
        Poroizvoljno,
        Gore,
        Dole,
        Levo,
        Desno,
        GoreLevo,
        GoreDesno,
        DoleLevo,
        DoleDesno
    }
}
